package com.zzh.rabbit;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import com.zzh.lib.core.HLibrary;
import com.zzh.lib.core.listener.HAppBackgroundListener;
import com.zzh.lib.core.utils.HFileUtils;
import com.zzh.lib.core.utils.LogUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import static com.zzh.rabbit.HLog.l_life;

/**
 * Created by ZZH on 2022/6/2.
 *
 * @Date: 2022/6/2
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description:
 */
public class App extends Application {
    public static String fileLog = HFileUtils.getPublicDownloadFile().getAbsolutePath() + "/zzh/test.log";
    ;

    @Override
    public void onCreate() {
        super.onCreate();
        HLibrary.setDebug(true);
        HLibrary.getInstance().init(this);


        registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {

            @Override
            public void onActivityPreCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
                l_life("-----Application中的-onActivityPreCreated-----" + activity.getClass().getName());
                ////Logger.setPathAndLog(fileLog, activity.getClass().getName());
            }

            @Override
            public void onActivityPostCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
                l_life("-----Application中的-onActivityPostCreated-----" + activity.getClass().getName());
                //Logger.setPathAndLog(fileLog, activity.getClass().getName());
            }

            @Override
            public void onActivityPreStarted(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPreStarted-----" + activity.getClass().getName());
                //Logger.setPathAndLog(fileLog, activity.getClass().getName());
            }

            @Override
            public void onActivityPostStarted(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPostStarted-----" + activity.getClass().getName());
                //Logger.setPathAndLog(fileLog, activity.getClass().getName());
            }

            @Override
            public void onActivityPreResumed(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPreResumed-----" + activity.getClass().getName());
                //Logger.setPathAndLog(fileLog, activity.getClass().getName());
            }

            @Override
            public void onActivityPostResumed(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPostResumed-----" + activity.getClass().getName());
                //Logger.setPathAndLog(fileLog, activity.getClass().getName());
            }

            @Override
            public void onActivityPrePaused(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPrePaused-----" + activity.getClass().getName());
                //Logger.setPathAndLog(fileLog, activity.getClass().getName());
            }

            @Override
            public void onActivityPostPaused(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPostPaused-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityPreStopped(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPreStopped-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityPostStopped(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPostStopped-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityPreSaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
                l_life("-----Application中的-onActivityPreSaveInstanceState-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityPostSaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
                l_life("-----Application中的-onActivityPostSaveInstanceState-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityPreDestroyed(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPreDestroyed-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityPostDestroyed(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPostDestroyed-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
                l_life("-----Application中的-onActivityCreated-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityStarted(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityStarted");
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityResumed(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityResumed-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityPaused(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityPaused-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityStopped(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityStopped-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, @NonNull Bundle outState) {
                l_life("-----Application中的-onActivitySaveInstanceState-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }

            @Override
            public void onActivityDestroyed(@NonNull Activity activity) {
                l_life("-----Application中的-onActivityDestroyed-----" + activity.getClass().getName());
                //Logger.log(activity.getClass().getName());
            }
        });
        HAppBackgroundListener.getInstance().addCallback(new HAppBackgroundListener.Callback() {
            @Override
            public void onBackground() {
                LogUtils.d("-------app 退到后台");
            }

            @Override
            public void onResumeFromBackground() {
                LogUtils.d("-------app 回到其他");
            }
        });
    }
}

